package com.yueyang.sojourn.server.service.member;

import com.yueyang.sojourn.server.model.po.MemberMerch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 会员商品service
 */
@Service
public class MemberMerchService {
    @Autowired
    private MemberMerchMapper memberMerchMapper;

    public void insert(MemberMerch memberMerch) {
        this.memberMerchMapper.insert(memberMerch);
    }

    public MemberMerch findById(Integer id) {
        return this.memberMerchMapper.selectByPrimaryKey(id);
    }

    public void delete(Integer id) {
        this.memberMerchMapper.deleteByPrimaryKey(id);
    }

    /**
     * 获取默认的可购买会员信息
     * @return
     */
    public MemberMerch findDefault() {
        MemberMerchExample memberMerchExample = new MemberMerchExample();
        memberMerchExample.setOrderByClause("id asc");
        memberMerchExample.createCriteria().andStateEqualTo((byte) 1);
        return this.memberMerchMapper.selectByExample(memberMerchExample).stream().findFirst().orElse(null);
    }
}
